home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.table;
-
- import com.sun.java.swing.JLabel;
- import com.sun.java.swing.JTable;
- import java.awt.Component;
- import java.beans.PropertyChangeListener;
- import java.beans.PropertyChangeSupport;
- import java.io.Serializable;
-
- public class TableColumn implements Serializable {
- public static final String COLUMN_WIDTH_PROPERTY = "columWidth";
- public static final String HEADER_VALUE_PROPERTY = "headerValue";
- public static final String HEADER_RENDERER_PROPERTY = "headerRenderer";
- public static final String CELL_RENDERER_PROPERTY = "cellRenderer";
- protected int modelIndex;
- protected Object identifier;
- protected int width;
- protected int minWidth;
- protected int maxWidth;
- protected TableCellRenderer headerRenderer;
- protected Object headerValue;
- protected TableCellRenderer cellRenderer;
- protected TableCellEditor cellEditor;
- protected boolean isResizable;
- protected transient int resizedPostingDisableCount;
- private PropertyChangeSupport changeSupport;
-
- public TableColumn() {
- this(0);
- }
-
- public TableColumn(int modelIndex) {
- this(modelIndex, 75, (TableCellRenderer)null, (TableCellEditor)null);
- }
-
- public TableColumn(int modelIndex, int width) {
- this(modelIndex, width, (TableCellRenderer)null, (TableCellEditor)null);
- }
-
- public TableColumn(int modelIndex, int width, TableCellRenderer cellRenderer, TableCellEditor cellEditor) {
- this.modelIndex = modelIndex;
- this.width = width;
- this.cellRenderer = cellRenderer;
- this.cellEditor = cellEditor;
- this.minWidth = 15;
- this.maxWidth = Integer.MAX_VALUE;
- this.isResizable = true;
- this.resizedPostingDisableCount = 0;
- this.setHeaderRenderer(this.createDefaultHeaderRenderer());
- this.headerValue = null;
- }
-
- public synchronized void addPropertyChangeListener(PropertyChangeListener listener) {
- if (this.changeSupport == null) {
- this.changeSupport = new PropertyChangeSupport(this);
- }
-
- this.changeSupport.addPropertyChangeListener(listener);
- }
-
- protected TableCellRenderer createDefaultHeaderRenderer() {
- DefaultTableCellRenderer label = new 1();
- ((JLabel)label).setHorizontalAlignment(0);
- return label;
- }
-
- public void disableResizedPosting() {
- ++this.resizedPostingDisableCount;
- }
-
- public void enableResizedPosting() {
- --this.resizedPostingDisableCount;
- }
-
- public TableCellEditor getCellEditor() {
- return this.cellEditor;
- }
-
- public TableCellRenderer getCellRenderer() {
- return this.cellRenderer;
- }
-
- public TableCellRenderer getHeaderRenderer() {
- return this.headerRenderer;
- }
-
- public Object getHeaderValue() {
- return this.headerValue;
- }
-
- public Object getIdentifier() {
- return this.identifier != null ? this.identifier : this.getHeaderValue();
- }
-
- public int getMaxWidth() {
- return this.maxWidth;
- }
-
- public int getMinWidth() {
- return this.minWidth;
- }
-
- public int getModelIndex() {
- return this.modelIndex;
- }
-
- public boolean getResizable() {
- return this.isResizable;
- }
-
- public int getWidth() {
- return this.width;
- }
-
- public synchronized void removePropertyChangeListener(PropertyChangeListener listener) {
- if (this.changeSupport != null) {
- this.changeSupport.removePropertyChangeListener(listener);
- }
-
- }
-
- public void setCellEditor(TableCellEditor anEditor) {
- this.cellEditor = anEditor;
- }
-
- public void setCellRenderer(TableCellRenderer aRenderer) {
- TableCellRenderer oldRenderer = this.cellRenderer;
- this.cellRenderer = aRenderer;
- if (this.changeSupport != null) {
- this.changeSupport.firePropertyChange("cellRenderer", oldRenderer, this.cellRenderer);
- }
-
- }
-
- public void setHeaderRenderer(TableCellRenderer aRenderer) {
- TableCellRenderer oldRenderer = this.headerRenderer;
- if (aRenderer == null) {
- throw new IllegalArgumentException("Object is null");
- } else {
- this.headerRenderer = aRenderer;
- if (this.changeSupport != null) {
- this.changeSupport.firePropertyChange("headerRenderer", oldRenderer, this.headerRenderer);
- }
-
- }
- }
-
- public void setHeaderValue(Object aValue) {
- Object oldValue = this.headerValue;
- this.headerValue = aValue;
- if (this.changeSupport != null) {
- this.changeSupport.firePropertyChange("headerValue", oldValue, this.headerValue);
- }
-
- }
-
- public void setIdentifier(Object anIdentifier) {
- this.identifier = anIdentifier;
- }
-
- public void setMaxWidth(int newMaxWidth) {
- this.maxWidth = newMaxWidth;
- if (this.maxWidth < 0) {
- this.maxWidth = 0;
- } else if (this.maxWidth < this.minWidth) {
- this.maxWidth = this.minWidth;
- }
-
- if (this.width > this.maxWidth) {
- this.setWidth(this.maxWidth);
- }
-
- }
-
- public void setMinWidth(int newMinWidth) {
- this.minWidth = newMinWidth;
- if (this.minWidth < 0) {
- this.minWidth = 0;
- }
-
- if (this.width < this.minWidth) {
- this.setWidth(this.minWidth);
- }
-
- }
-
- public void setModelIndex(int anIndex) {
- this.modelIndex = anIndex;
- }
-
- public void setResizable(boolean flag) {
- this.isResizable = flag;
- }
-
- public void setWidth(int newWidth) {
- int oldWidth = this.width;
- if (this.width != newWidth) {
- this.width = newWidth;
- if (this.width < this.minWidth) {
- this.width = this.minWidth;
- } else if (this.width > this.maxWidth) {
- this.width = this.maxWidth;
- }
-
- if (this.changeSupport != null) {
- this.changeSupport.firePropertyChange("columWidth", new Integer(oldWidth), new Integer(this.width));
- }
-
- }
- }
-
- public void sizeWidthToFit() {
- Component comp = this.getHeaderRenderer().getTableCellRendererComponent((JTable)null, this.getHeaderValue(), false, false, 0, 0);
- int headerWidth = comp.getPreferredSize().width;
- if (headerWidth > this.getMaxWidth()) {
- this.setMaxWidth(headerWidth);
- }
-
- if (headerWidth < this.getMinWidth()) {
- this.setMinWidth(headerWidth);
- }
-
- this.setWidth(headerWidth);
- }
- }
-